package com.sr.service.impl;

import com.sr.ibase.IBaseService;
import com.sr.ibase.impl.BaseServiceImpl;
import com.sr.pojo.WResources;
import com.sr.service.IResourcesService;
import com.sr.vo.req.ResourcesReqVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author xiaochi
 * @date 2022/4/30 13:31
 * @desc ResourcesServiceImpl
 */
@Service
public class ResourcesServiceImpl extends BaseServiceImpl<WResources> implements IResourcesService {

    /**
     * 判断资源是否存在
     * @param reqVo
     * @return
     */
    public boolean hasExistsByName(ResourcesReqVo reqVo, String memerId){
        IBaseService.Criteria<WResources> criteria = this.createCriteria(WResources.class);
        criteria.andEqualTo(WResources::getName,reqVo.getName())
                .andEqualTo(WResources::getMemberId,memerId)
                .andNotEqualTo(WResources::getId,!StringUtils.isEmpty(reqVo.getId()),reqVo.getId());
        return this.count(criteria) > 0;
    }
}
